{include file="public_head" /}
<!-- upload -->
<link href="__STATIC__/css/uploads.css" rel="stylesheet">
<!-- Select2 -->
<link href="__STATIC__/css/select/select2.min.css" rel="stylesheet">


<body class="nav-md">

<div class="container body">

    <div class="main_container">

        {include file="public_sidebar,public_nav" /}
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">

                <div class="page-title">
                    <!--<div class="title_left">-->
                    <!--<h3>广告位管理</h3>-->
                    <!--</div>-->
                </div>
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>使用会员卡
                                    <!--<small>different form elements</small>-->
                                </h2>
                                <ul class="nav navbar-right panel_toolbox">
                                    <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                    </li>
                                    <li><a class="close-link"><i class="fa fa-close"></i></a>
                                    </li>
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <br/>
                                <form class="form-horizontal form-label-left" enctype="multipart/form-data" action="" method="post" id="registerForm">

                                    <!--<div class="form-group">-->
                                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">服务分类：</label>-->
                                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                                            <!--<select name="parent_id" class="select2_single"-->
                                                    <!--style="width: 500px;" tabindex="-1"-->
                                                    <!--datatype="*"-->
                                                    <!--nullmsg="请选择栏目分类！" errormsg="请选择栏目分类！"-->
                                            <!--&gt;-->
                                                <!--{volist name="news_type" id="item"}-->
                                                <!--<option value="{item.id}"-->

                                                <!--&gt;-->
                                                <!--{neq name="$item.level" value="1"}{:str_repeat('&nbsp&nbsp',$item.level)}{/neq}|{:str_repeat('&#45;&#45;',$item.level)}{$item.cat_name}-->
                                                <!--</option>-->
                                                <!--{/volist}-->
                                            <!--</select>-->
                                        <!--</div>-->
                                    <!--</div>-->

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">(认证车牌号)-会员卡选择：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select name="card_id" class="select2_single" onchange="shuaxin(this.value)"
                                                    style="width: 100%;" tabindex="-1"
                                                    datatype="*"
                                                    nullmsg="请选择会员卡！" errormsg="请选择会员卡！"
                                            >
                                                {volist name="data" id="item2"}
                                                <option value="{$item2.id}" {eq name="$item2.id" value=":input('card_id')"}selected{/eq}>
                                                {$item2.order_id}-
                                                <!--{if condition="$item2.is_certification eq 2 && $item2.type == 1"}({$item2.car_number})-{/if}-->
                                                车牌:({$item2.car_number})
                                                {$item2.id}-
                                                {switch name="$item2.type"}
                                                    {case 1}年卡{/case}
                                                    {case 2}次卡{/case}
                                                    {/switch}
                                                    {$item2.title}
                                                    -到期时间:{$item2.end_time}  {if condition="strtotime($item2.end_time) lt time()"} 已过期{/if}
                                                </option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group service_people tc">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">会员卡详情：</label>
                                        <div class="col-md-7 col-sm-6 col-xs-12" style="margin-top: 10px;">
                                            <table width="100%" border="1" style="font-family: '微软雅黑';">
                                                <tr align="center" style="font-size: 16px;">
                                                    <td width="160">服务分类</td>
                                                    <td width="160">服务内容</td>
                                                    <td width="90">会员卡总次数(剩余次数)</td>
                                                </tr>
                                                {volist name='order_gift_count' id='vo'}
                                                <tr align="center">
                                                    <td>{$vo.cat_name|default=''}</td>
                                                    <td>{$vo.cat_name2|default=''}</td>
                                                    <td>{$vo.gift_origin_count|default=''}({$vo.gift_count|default=''})</td>
                                                </tr>
                                                {/volist}
                                            </table>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">服务人员与提成：</label>
                                        <div class="col-md-8 col-sm-6 col-xs-12" style="margin-top: 10px;">
                                            <table width="100%" border="1" style="font-family: '微软雅黑';">
                                                <tr align="center" style="font-size: 16px;">
                                                    <td width="160">服务门店</td>

                                                    <td width="100">标题</td>
                                                    <td width="70">服务人员</td>
                                                    <td width="100">服务类型</td>
                                                    <td width="150">服务内容</td>
                                                    <td width="70">提成金额</td>
                                                    <td width="150">消费日期</td>

                                                    <td width="150">用户是否确认使用</td>
                                                </tr>
                                                {volist name='member_card_records' id='vo'}
                                                <tr align="center">
                                                    <td>{$vo.shop_title|default=''}</td>

                                                    <td>{$vo.title}</td>
                                                    <td>{$vo.shop_assignor_name|default=''}</td>
                                                    <td>{$vo.single_title1}</td>
                                                    <td>{$vo.service_content|default=''}</td>
                                                    <td>{$vo.price|default=''}</td>
                                                    <td>{$vo.create_time|default=''}</td>
                                                    <td>
                                                        {switch name="$vo.is_agree"}
                                                        {case 1}未确认{/case}
                                                        {case 2}已确认{/case}
                                                        {/switch}
                                                    </td>
                                                    <!--<td>{$vo.name|default=''}</td>-->
                                                    <!--<td>{$vo.assignor_price|default=''}</td>-->
                                                    <!--<td>{$vo.create_time|default=''}</td>-->
                                                    <!--<td>{$vo.assignor_content|default=''}</td>-->
                                                    <!--<td onclick="del({$vo.id})">删除</td>-->
                                                </tr>
                                                {/volist}
                                            </table>
                                        </div>
                                    </div>
                                    {eq name=":session('auding_status')" value="1"}
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">服务人员提成：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <table class="table table-striped table-bordered table-hover">
                                                <thead>
                                                <th>服务人员</th>
                                                <th>服务分类</th>
                                                <th>服务内容</th>
                                                <th>提成金额</th>
                                                <th>操作</th>
                                                </thead>
                                                <tbody id="fieldtr">

                                                <tbody align="right">
                                                <tr>
                                                    <td colspan="5"><a href="javascript:;" class="addNewTr" title="新增一条">新增一条</a></td>
                                                </tr>
                                                </tbody>

                                            </table>
                                        </div>
                                    </div>
                                    {/eq}
                                    {eq name=":session('auding_status')" value="2"}
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">服务人员提成：</label>
                                        <div class="col-md-7 col-sm-6 col-xs-12">
                                            <table class="table table-striped table-bordered table-hover">
                                                <thead>
                                                <th>服务门店</th>
                                                <th>服务人员</th>
                                                <th>服务分类</th>
                                                <th>服务内容</th>
                                                <th>提成金额</th>
                                                <th>操作</th>
                                                </thead>
                                                <tbody id="fieldtr">

                                                <tbody align="right">
                                                <tr>
                                                    <td colspan="6"><a href="javascript:;" class="addNewTrshop" title="新增一条">新增一条</a></td>
                                                </tr>
                                                </tbody>

                                            </table>
                                        </div>
                                    </div>
                                    {/eq}



                                    <!--<div class="form-group">-->
                                    <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">描    述：</label>-->
                                    <!--<div class="col-md-1 col-sm-6 col-xs-12">-->
                                    <!--<textarea name="describe" rows="5" style="width: 300px;" >{$item.describe|default=''}</textarea>-->
                                    <!--</div>-->
                                    <!--</div>-->




                                    <!--<div class="form-group">-->
                                    <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">排　　序：</label>-->
                                    <!--<div class="col-md-1 col-sm-6 col-xs-12">-->
                                    <!--<input type="text" placeholder="请填写排序"-->
                                    <!--class="form-control col-md-7 col-xs-12" name="sort"-->
                                    <!--value="{$item.sort|default='0'}"-->
                                    <!--&gt;-->
                                    <!--</div>-->
                                    <!--</div>-->

                                    <div class="form-group">
                                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                                            <button type="submit" class="btn btn-primary">提交</button>
                                            <a type="reset" class="btn btn-success" onclick="window.location.href='{:url(\'card\',[\'username\' => input(\'username\')])}'">返回</a>
                                        </div>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
            <!-- /page content -->

        </div>

    </div>
</div>

{include file="public_foot" /}

<!-- Datatables-->
<script src="__STATIC__/js/datatables/jquery.dataTables.min.js"></script>
<script src="__STATIC__/js/datatables/dataTables.bootstrap.js"></script>
<!-- validform -->
<script src="__STATIC__/js/Validform_v5.3.2_min.js"></script>
<script src="__STATIC__/js/layer.js"></script>
<!--select-->
<script src="__STATIC__/js/select/select2.full.min.js"></script>
<!--upload-->
<script type="text/javascript" src="__STATIC__/js/uploadPreview.js"></script>

<!-- ueditor -->
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/lang/zh-cn/zh-cn.js"></script>
<script>
    //upload
    function shuaxin(card_id) {

        var domain = document.domain;
        window.location.href = 'http://'+domain+'/index.php/console/shop/member_card/username/'+{:input('username')}+'.html?card_id='+card_id;

    }
    window.onload = function () {
        new uploadPreview({UpBtn: "up_img", DivShow: "imgdiv", ImgShow: "imgShow"});
    }

    $("[name='parent_idd']").change(function(){
        ''
        var v = $(this).val();
        if(v == 5 || v==10){
            var str = '<div class="form-group">\n' +
                '                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">网址：</label>\n' +
                '                                        <div class="col-md-6 col-sm-6 col-xs-12">\n' +
                '                                            <input type="text" placeholder="请输入网址"\n' +
                '                                                   class="form-control col-md-7 col-xs-12" name="web_url"\n' +
                '                                                   value="{$item.web_url|default=\'\'}"\n' +
                '                                                   datatype="*"\n' +
                '                                                   nullmsg="请输入网址！" errormsg="请输入网址"\n' +
                '                                            >\n' +
                '                                        </div>\n' +
                '                                    </div>'
        }else{
            var str = '<div class="form-group">\n' +
                '                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">图片上传：【800*800】</label>\n' +
                '                                        <div class="col-md-6 col-sm-6 col-xs-12">\n' +
                '                                            <div id="imgdiv">\n' +
                '                                                <img id="imgShow" src="__PUBLIC__/{$item.pic_url|default=\'\'}"\n' +
                '                                                     width="200" height="190"\n' +
                '                                                     onerror="this.src=\'__STATIC__/images/default.png\'"/>\n' +
                '                                            </div>\n' +
                '                                            <div class="uploader white">\n' +
                '                                                <input type="text" class="filename" name="pic_url"\n' +
                '                                                       value="{$item.pic_url|default=\'\'}" readonly/>\n' +
                '                                                <input type="button" name="file" class="button" value="上传..."/>\n' +
                '                                                <input type="file" id="up_img" name="pic_url"\n' +
                '                                                       value=\'{$item.pic_url|default=""}\'/>\n' +
                '                                            </div>\n' +
                '                                        </div>\n' +
                '                                    </div>\n' +
                '\n' +
                '                                    <div class="form-group">\n' +
                '                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">新闻内容：</label>\n' +
                '                                        <div class="col-md-6 col-sm-6 col-xs-12">\n' +
                '                                           <textarea type="text/plain" style="height: 300px; width: 100%" id="containers"\n' +
                '                                                     name="content"\n' +
                '                                                     placeholder="请输入信息内容">\n' +
                '                                                {$item.content|default=\'\'}\n' +
                '                                            </textarea>\n' +
                '                                        </div>\n' +
                '                                    </div>';





        }
        $.getScript("__STATIC__/editor/ueditor.config.js",function(){  //加载test.js,成功后，并执行回调函数  console.log("加载js文件");
            //alert(1);
        });
        $.getScript("__STATIC__/editor/ueditor.all.min.js",function(){  //加载test.js,成功后，并执行回调函数  console.log("加载js文件");
            //alert(2);
        });
        $.getScript("__STATIC__/editor/lang/zh-cn/zh-cn.js",function(){  //加载test.js,成功后，并执行回调函数  console.log("加载js文件");
            //alert(3);
        });
        var ue = UE.getEditor('containers');
        $('#c').html(str);
        window.onload = function () {
            new uploadPreview({UpBtn: "up_img", DivShow: "imgdiv", ImgShow: "imgShow"});
        }

    });
    // 实例化编辑器
    var ue = UE.getEditor('containers');
    //validform
    $(function () {

        $.Tipmsg.r = null;

        var showmsg = function (msg) {
            //假定你的信息提示方法为showmsg， 在方法里可以接收参数msg，当然也可以接收到o及cssctl;
            alert(msg);
        }
        $("#registerForm").Validform({
            tiptype: function (msg) {
                layer.msg(msg);
            },
            tipSweep: true
        });


        // select2
        $(".select2_single").select2({
            placeholder: "请选择分类",
            allowClear: true
        });

        $(".select2_multiple").select2({
            maximumSelectionLength: 0,
            placeholder: "请选择关联品牌",
            allowClear: true
        });

    })

    var assgioner = {$shop_assignor};
    var ss = [];
    $.each(assgioner, function(k,v){
        ss += '<option value="'+v.id+'">'+v.name+'</option>';
    });
    var gift_c;
    $.each({$now_gift_count}, function(k,v){ //服务人员提成
        gift_c += '<option value="'+v.id+'">'+v.cat_name+'</option>';
    });
    var gift_shop_content;
    $.each({$service_people_price2}, function(k,v){ //服务人员提成
        gift_shop_content += '<option value="'+v.id+'">'+v.cat_name+'</option>';
    });
    $(".addNewTr").click(function(){
        str = '<tr><td><select name="assignor_id[]" class="form-control" tabindex="-1">' + ss +
            '</select></td>' +
            '<td><select name="single_id[]" onchange="single2(this.value,this)" class="form-control" tabindex="-1">' + gift_c +
            '<td><select name="assignor_content[]" onchange="person_price(this.value,this)" class="form-control" tabindex="-1">' + gift_shop_content +
            '<td><input name="assignor_price[]" readonly class="form-control" value="'+{$service_people_price2}[0]['person_price']+'" /></td>'+
            '<td><a href="javascript:;" onclick="delThisTr($(this))">删除</a></td></tr>';
        $("#fieldtr").append(str);
    });

    function single2(id,t) { //获得2级类以及价格
        var shop_id = 0;
        var order_id = "{$order_id}";
        if({:session('auding_status')} == 1){
            shop_id = "{:session('shop_id')}";
        }else{
            shop_id = $(t).parent().prev().prev().find('select').val();
        }
        $.ajax({
            url : '{:url("single/ajax2")}',
            data:{'id':id,'shop_id':shop_id,'order_id':order_id,'t_type':2},
            dataType:'json',
            success:function(data){
                var str = [];
                console.log(data);
                str = '<select name="assignor_content[]" onchange="person_price(this.value,this)" class="form-control" tabindex="-1">';
                $.each(data, function(k,v){
                    str += '<option value="'+v.id+'">'+v.cat_name+'</option>';
                });
                str += '</select>';
                $(t).parent().next().html(str);
                var person_price = [];
                person_price = '<td><input name="assignor_price[]" readonly class="form-control" value="'+data[0]['person_price']+'" /></td>';
                $(t).parent().next().next().html(person_price);
                console.log(person_price);
            }
        });
    }

    function person_price(id,t) { //二级类获得字的价格
        if({:session('auding_status')} == 1){
            var shop_id = "{:session('shop_id')}";
        }else{
            var shop_id = $(t).parent().prev().prev().prev().find('select').val();
        }
        $.ajax({
            url : '{:url("single/ajax4")}',
            data:{'id':id,'shop_id':shop_id},
            dataType:'json',
            success:function(data){
                console.log(data);
                var person_price = [];
                person_price = '<td><input name="assignor_price[]" readonly class="form-control" value="'+data+'" /></td>';
                $(t).parent().next().html(person_price);
            }
        });
    }


    var sss = [];//门店list
    var shop_list = {$shop_list};
    $.each(shop_list, function(k,v){
        sss += '<option value="'+v.id+'">'+v.shop_title+'</option>';
    });
    var gift_d;
    $.each({$now_gift_count}, function(k,v){ //礼包
        gift_d += '<option value="'+v.id+'">'+v.cat_name+'</option>';
    });
    $(".addNewTrshop").click(function(){
        str = '<tr><td><select onchange="shop(this.value,this)" name="shop_id[]" class="form-control" tabindex="-1">' + sss+
            '</select><td id="assignor_id"><select name="assignor_id[]" class="form-control" tabindex="-1">' + ss +
            '</select></td>' +
            '<td id="server_people_price"><select name="single_id[]" onchange="single2(this.value,this)" class="form-control" tabindex="-1">' + gift_c +
            '</select></td>' +
            '<td><select name="assignor_content[]" onchange="person_price(this.value,this)" class="form-control" tabindex="-1">' + gift_shop_content +
            '<td><input name="assignor_price[]" readonly class="form-control" value="'+{$service_people_price2}[0]['person_price']+'" /></td>'+
            '<td><a href="javascript:;" onclick="delThisTr($(this))">删除</a></td></tr>';
        $("#fieldtr").append(str);
    });
    function delThisTr(trobj)
    {
        trobj.parent().parent().remove();
    }
    function shop(id,t){
        //人员切换
        $.ajax({
            url : '{:url("gift_order/shop_assignor")}',
            data:{'shop_id':id},
            dataType:'json',
            success:function(data){
                var str = [];
                console.log(data);
                str = '<select name="assignor_id[]" class="form-control" tabindex="-1">';
                $.each(data, function(k,v){
                    str += '<option value="'+v.id+'">'+v.name+'</option>';
                });
                str += '</select>';
                $('#assignor_id').html(str);
                console.log(str);
            }
        });
        var order_id  = "{:input('order_id')}";
        //服务类切换
        $.ajax({ //当前礼包一级类
            url : '{:url("gift_order/now_gift_count")}',
            data:{'shop_id':id,'order_id':order_id,t_type:2},
            dataType:'json',
            success:function(data){
                var str = [];
                console.log(data);
                str = '<select name="single_id[]" onchange="single2(this.value,this)" class="form-control" tabindex="-1">';
                $.each(data.one_level, function(k,v){
                    str += '<option value="'+v.id+'">'+v.cat_name+'</option>';
                });
                str += '</select>';
                $(t).parent().next().next().html(str);
                var assignor_content = '<select name="assignor_content[]" onchange="person_price(this.value,this)" class="form-control" tabindex="-1">';
                $.each(data.two_level, function(k,v){
                    assignor_content += '<option value="'+v.id+'">'+v.cat_name+'</option>';
                });
                assignor_content += '</select>';
                $(t).parent().next().next().next().html(assignor_content);
                var assignor_price = '<input name="assignor_price[]" readonly class="form-control" value="'+data['two_level'][0]['person_price']+'" />';
                $(t).parent().next().next().next().next().html(assignor_price);

            }
        });
    }
</script>
</body>

</html>
